package com.zrwl.poscloud.core.restapi.admin.others;

import com.zrwl.poscloud.core.annotion.AuthorityVerify.AuthorityVerify;
import com.zrwl.poscloud.core.annotion.OperationLogger.OperationLogger;
import com.zrwl.poscloud.commons.exception.ThrowableUtils;
import com.zrwl.poscloud.commons.holder.RequestHolder;
import com.zrwl.poscloud.commons.utils.ResultUtil;
import com.zrwl.poscloud.commons.validator.group.Delete;
import com.zrwl.poscloud.commons.validator.group.GetList;
import com.zrwl.poscloud.commons.validator.group.Insert;
import com.zrwl.poscloud.commons.validator.group.Update;
import com.zrwl.poscloud.xo.global.SysConf;
import com.zrwl.poscloud.xo.service.CompanyPayConfigService;
import com.zrwl.poscloud.xo.vo.CompanyPayConfigVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 在线支付商户信息 controller api类
 *
 * @author 刘思童 AutoGenerate
 * @date 2021-06-11
 */
@RestController
@Api(value = "在线支付商户信息相关接口", tags = {"在线支付商户信息相关接口"})
@RequestMapping("/companyPayConfig")
@Slf4j
public class CompanyPayConfigRestApi {

    @Autowired
    private CompanyPayConfigService companyPayConfigService;

    @AuthorityVerify
    @ApiOperation(value = "获取在线支付商户信息列表", notes = "获取在线支付商户信息列表", response = String.class)
    @PostMapping("/getList")
    public String getList(@Validated({GetList.class}) @RequestBody CompanyPayConfigVO companyPayConfigVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("获取在线支付商户信息列表: {}", companyPayConfigVO);
        return ResultUtil.successWithData(companyPayConfigService.getPageList(companyPayConfigVO));
    }

    @AuthorityVerify
    @ApiOperation(value = "获取在线支付商户信息列表", notes = "获取在线支付商户信息列表", response = String.class)
    @PostMapping("/getAllList")
    public String getAllList(@Validated({GetList.class}) @RequestBody CompanyPayConfigVO companyPayConfigVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("获取在线支付商户信息列表: {}", companyPayConfigVO);
        return ResultUtil.successWithData(companyPayConfigService.getAllList(companyPayConfigVO));
    }

//    @AuthorityVerify
//    @OperationLogger(value = "新增在线支付商户信息")
//    @ApiOperation(value = "新增在线支付商户信息", notes = "新增在线支付商户信息", response = String.class)
//    @PostMapping("/add")
//    public String add(@Validated({Insert.class}) @RequestBody CompanyPayConfigVO companyPayConfigVO, BindingResult result) {
//        ThrowableUtils.checkParamArgument(result);
//        log.info("新增在线支付商户信息: {}", companyPayConfigVO);
//        return companyPayConfigService.add(companyPayConfigVO);
//    }
//
//    @AuthorityVerify
//    @OperationLogger(value = "修改在线支付商户信息")
//    @ApiOperation(value = "修改在线支付商户信息", notes = "修改在线支付商户信息", response = String.class)
//    @PostMapping("/edit")
//    public String edit(@Validated({Update.class}) @RequestBody CompanyPayConfigVO companyPayConfigVO, BindingResult result) {
//        ThrowableUtils.checkParamArgument(result);
//        log.info("修改在线支付商户信息: {}", companyPayConfigVO);
//        return companyPayConfigService.edit(companyPayConfigVO);
//    }
//
//    @AuthorityVerify
//    @OperationLogger(value = "删除在线支付商户信息")
//    @ApiOperation(value = "删除在线支付商户信息", notes = "删除在线支付商户信息", response = String.class)
//    @PostMapping("/delete")
//    public String delete(@Validated({Delete.class}) @RequestBody CompanyPayConfigVO companyPayConfigVO, BindingResult result) {
//        ThrowableUtils.checkParamArgument(result);
//        log.info("删除在线支付商户信息: {}", companyPayConfigVO);
//        return companyPayConfigService.delete(companyPayConfigVO);
//    }

    @AuthorityVerify
    @OperationLogger(value = "修改在线支付商户信息本地服务器")
    @ApiOperation(value = "修改在线支付商户信息本地服务器", notes = "修改在线支付商户信息本地服务器", response = String.class)
    @PostMapping("/editLocal")
    public String editLocal(@Validated({Update.class}) @RequestBody CompanyPayConfigVO companyPayConfigVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("修改在线支付商户信息本地服务器: {}", companyPayConfigVO);
        return companyPayConfigService.editLocal(companyPayConfigVO);
    }

    @AuthorityVerify
    @ApiOperation(value = "获取在线支付商户信息列表", notes = "获取在线支付商户信息列表", response = String.class)
    @PostMapping("/getCompanyPayConfigList")
    public String getCompanyPayConfigList(@Validated({GetList.class}) @RequestBody CompanyPayConfigVO companyPayConfigVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("获取在线支付商户信息列表: {}", companyPayConfigVO);
        return ResultUtil.successWithData(companyPayConfigService.getCompanyPayConfigList(companyPayConfigVO));
    }

    @AuthorityVerify
    @ApiOperation(value = "获取当前在线支付商户信息列表", notes = "获取当前在线支付商户信息列表", response = String.class)
    @PostMapping("/getPresentCompanyPayConfigList")
    public String getPresentCompanyPayConfigList(@Validated({GetList.class}) @RequestBody CompanyPayConfigVO companyPayConfigVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        HttpServletRequest request = RequestHolder.getRequest();
        companyPayConfigVO.setOwnerUid(request.getAttribute(SysConf.OWNER_UID).toString());
        log.info("获取当前在线支付商户信息列表: {}", companyPayConfigVO);
        return ResultUtil.successWithData(companyPayConfigService.getCompanyPayConfigList(companyPayConfigVO));
    }

}
